package cn.chyn.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    // ip 改自己服务器的
    public static final String BASE_URL = "http://192.168.232.136";
    @Override
    public void addCorsMappings(CorsRegistry registry) {
//        registry.addMapping("/**")
//                .allowedOrigins("http://localhost:5173", "http://192.168.232.132:80", "http://192.168.232.132"
//                        , "http://192.168.52.1:5173", "http://192.168.1.103:5173", "http://192.168.232.1:5173")  // 使用逗号分隔多个地址
//                .allowedMethods("GET", "POST", "PUT", "DELETE")
//                .allowedHeaders("*");


        registry.addMapping("/**")
                .allowedOrigins("http://localhost:5173", BASE_URL+":80", BASE_URL
//                        , "http://192.168.52.1:5173", "http://192.168.1.103:5173", "http://192.168.232.1:5173"
                )  // 使用逗号分隔多个地址
                .allowedMethods("GET", "POST", "PUT", "DELETE")
                .allowedHeaders("*");
    }
}
